
/*
 * @Author: zhuxiaoyi
 * @Date: 2021-11-01 09:38:29
 * @LastEditor: zhuxiaoyi
 * @LastEditTime: 2022-04-06 15:58:40
 * @Description:
 */
const utils = {
  setLocalStorage: function (name: string, value: any) {
    let storage;
    if (!name || !value) return;
    if (typeof value !== "string") {
      value = JSON.stringify(value);
    }
    storage = window.localStorage.setItem(name, value);
  },
  getLocalStorage: function (name: string) {
    if (!name) return;
    return window.localStorage.getItem(name);
  },
  setSessionStroage: function (name: string, value: any) {
    if (!name) return;
    if (typeof value !== "string") {
      value = JSON.stringify(value);
    }
    window.sessionStorage.setItem(name, value);
  },
  getSessionStroage: function (name: string) {
    if (!name) return;
    return window.sessionStorage.getItem(name);
  },
  removeSessionStroage: function (name: string) {
    if (!name) return;
    return window.sessionStorage.removeItem(name);
  },
  setTooken(token: string) {
    utils.setLocalStorage("token", token);
  },
  getTooken() {
    let token: any = null;
    token = utils.getLocalStorage("token");
    return token;
  },
  clearToken() {
    window.localStorage.removeItem("token");
  },
  urlEncode: function (param: any, key?: any, encode?: any) {
    if (param == null) return "";
    var paramStr = "";
    var t = typeof param;
    if (t == "string" || t == "number" || t == "boolean") {
      paramStr +=
        "&" +
        key +
        "=" +
        (encode == null || encode ? encodeURIComponent(param) : param);
    } else {
      for (var i in param) {
        var k =
          key == null
            ? i
            : key + (param instanceof Array ? "[" + i + "]" : "." + i);
        paramStr += this.urlEncode(param[i], k, encode);
      }
    }
    return paramStr;
  },
  checkType: function (data: any) {
    return Object.prototype.toString.call(data);
  },
  formatDate(dateTime) {
    let date = new Date(dateTime);
    let YY = date.getFullYear() + "-";
    let MM =
      (date.getMonth() + 1 < 10
        ? "0" + (date.getMonth() + 1)
        : date.getMonth() + 1) + "-";
    let DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    let hh =
      (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
    let mm =
      (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
      ":";
    let ss =
      date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
    return YY + MM + DD + " " + hh + mm + ss;
  },
  formatDateDay(dateTime) {
    let date = new Date(dateTime);
    let YY = date.getFullYear() + "-";
    let MM =
      (date.getMonth() + 1 < 10
        ? "0" + (date.getMonth() + 1)
        : date.getMonth() + 1) + "-";
    let DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    let hh =
      (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
    let mm =
      (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
      ":";
    let ss =
      date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
    return YY + MM + DD;
  },
  getCurrentTime() {
    //获取当前时间并打印
    let gettime = "";
    let yy = new Date().getFullYear();
    let mm = new Date().getMonth() + 1;
    let dd = new Date().getDate();
    let hh = new Date().getHours();
    let mf =
      new Date().getMinutes() < 10
        ? "0" + new Date().getMinutes()
        : new Date().getMinutes();
    let ss =
      new Date().getSeconds() < 10
        ? "0" + new Date().getSeconds()
        : new Date().getSeconds();
    gettime = yy + "-" + mm + "-" + dd + " " + hh + ":" + mf + ":" + ss;
    return gettime;
  },
  calcTime: {
    data: {},
    ids: 0,
    start: function () {
      this.ids++;
      this.data[this.ids] = new Date().getTime();
      return this.ids;
    },
    end: function (id) {
      var item = this.data[id];
      if (item === undefined) {
        console.log("id错误");
        return;
      }
      delete this.data[id];
      return new Date().getTime() - item;
    },
  },

};

export default utils

export const minio = "/minio/"
